//
//  ViewController.swift
//  Swift_base_grammar
//
//  Created by lantaiyuan on 2017/9/13.
//  Copyright © 2017年 lantaiyuan. All rights reserved.
//

import UIKit

class ViewController: UIViewController {


    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        self.navigationItem.rightBarButtonItem = UIBarButtonItem.init(title: "网络", style: .plain, target: self, action: #selector(rightItemAction))
        
        //1.语句并列
        let a = 10;let b = 20
        //5.打印
        print(a + b)
        
        //2.创建view对象 并指定位置
        let subView = UIView.init(frame: CGRect(x:15,y:80,width:100,height:100))
        //3.背景颜色
        subView.backgroundColor = UIColor.red
        view.addSubview(subView)
        
        //创建button --- 枚举
        let button = UIButton.init(type: .contactAdd)
        button.center = view.center
        view.addSubview(button)
        
        //添加监听方法
        button.addTarget(self, action: #selector(click(_:)), for: .touchUpInside)
        
        //常量和变量
//        demo()
//        demo1()
//        demo2()
//        demo3()
        
        //控制流
//        control1(5)
//        control2(10)
//        control3()
//        control4()
        
        //可选项替换
//        optional()
        
        
        //字符串操作
        //string1()
        //string2()
        //string3()
        //string4()
        //string5()
        //string6()
        
        //循环
        //loop1()
        
        //集合
//        array()
//        mutableArr()
//        loopArray()
//        operatorArr()
//        testCapacity()
//        array3()
//        dict()
//        dict2()
//        dictAppend()
        
        //函数
//        NoReturnValue1()
//        print(returnValue(num1: 5, num2: 3))
//        print(returnValue2(2, 3))
//        print(sum(x: 1, y: 2))
        
        
        //闭包
//        print(sumFunc(100,150))
//        print(sumFunc2(100,120))
//        print(sumFunc3(100,119))
//        print(sumFunc4())//无参
//        sumFunc5()//无参
//        print(sumFunc6(10,20))
//        
//        funcDemo()//无参无返回值
        
        
//        loadData {
//            print("闭包使用")
//        }
        
//        loadData2 { (html) in
//            print(html)
//        }
//        loadData3()
        //闭包循环引用问题
        //CircularReference()
//        CircularReference2()
        
        //02-01网络请求
         //datatask()
        
        //getter && setter
//        let student = Student()
//        student.name = "张三"
//        print(student.name)
        
        //计算型属性
//        student._name2 = "李四"
//        print(student.name2)
//        //懒加载
//        print(student.name3)
        
//        print("-------")
//        student._name2 = nil
//        student._name2 = "王五"
//        print(student.name2)
//        //懒加载
//        print(student.name3)
        
        
        
        //构造函数
//        let student1 = Student1.init(name: "鲁班", age: 16, no: "007")
//        print(student1.name,student1.age,student1.no)
        
//        let student2 = Student1.init(dict: ["name":"田田" as AnyObject,"age":19 as AnyObject,"no":"008" as AnyObject])
//        
//        print(student2.name!,student2.age,student2.no!)
        
        let p = Student1.init(dict: ["name":"芈月" as AnyObject,"age":90 as AnyObject])
        print("-------\(p.name ?? ""),\(p.age)")
    }
    func click(_ sender:UIButton) {
        print("点我了\(sender)")
    }
    
    func rightItemAction() {
        let personVc = PersonViewController()
        self.navigationController?.pushViewController(personVc, animated: true)
    }
    
    deinit {
        print("拜拜 控制器")
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

